// 分享内容提供逻辑.
import {ShareContentProvider} from "../../framework/wx/ShareUtil";
import {globalConfig} from "../consts/GlobalConfig";
import CommonUtil from "../../framework/utils/CommonUtil";
import {wxApi} from "../api/WxApi";

export class DefaultShareProvider implements ShareContentProvider {

    private readonly _imageRes: string = `${globalConfig.resBaseUrl}/mfwd/res/shares/`;
    private readonly _texts: string[] = ["好玩的打僵尸游戏，根本停不下来！"];
    private readonly _imgs: string[] = ["share1.png"];
    private _index: number = 0;

    public getIndex(): number {
        return this._index;
    }

    public getText(): string {
        let txts = this._texts;
        if (globalConfig.shareDates && globalConfig.shareDates.txts) {
            txts = this._texts.concat(globalConfig.shareDates.txts);
        }
        this._index = CommonUtil.randomIndex(txts.length);
        return txts[this._index];
    }

    public getImage(): string {
        let imgs = this._imgs;
        if (globalConfig.shareDates && globalConfig.shareDates.imgs) {
            imgs = this._imgs.concat(globalConfig.shareDates.imgs);
        }
        let baseUrl = globalConfig.shareDates.baseUrl;
        if (!baseUrl || baseUrl.length <= 0) {
            baseUrl = this._imageRes;
        }
        let mode = globalConfig.shareDates.mode || 0;
        if (mode != 0) {
            this._index = CommonUtil.randomIndex(imgs.length);
        }
        return baseUrl + imgs[this._index];
    }

    public decryptGroupInfo(iv: string, data: string): Promise<any> {
        return wxApi.decryptGroupInfo(iv, data)
    }
}